home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_Value_Output.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.8 KB  |  99 lines

  1. //
  2. // "$Id: Fl_Value_Output.cxx,v 1.6 1999/01/07 19:17:28 mike Exp $"
  3. //
  4. // Value output widget for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Fltk widget for drag-adjusting a floating point value.
  27. // This is much lighter than Fl_Value_Input because it has no text editor
  28. // If step() is zero then it can be used to display a floating-point value
  29.  
  30. #include <FL/Fl.H>
  31. #include <FL/Fl_Value_Output.H>
  32. #include <FL/fl_draw.H>
  33.  
  34. void Fl_Value_Output::draw() {
  35.   Fl_Boxtype b = box() ? box() : FL_DOWN_BOX;
  36.   int X = x()+Fl::box_dx(b);
  37.   int Y = y()+Fl::box_dy(b);
  38.   int W = w()-Fl::box_dw(b);
  39.   int H = h()-Fl::box_dh(b);
  40.   if (damage()&~FL_DAMAGE_CHILD)
  41.     draw_box(b, color());
  42.   else {
  43.     fl_color(color());
  44.     fl_rectf(X, Y, W, H);
  45.   }
  46.   char buf[128];
  47.   format(buf);
  48.   fl_color(active_r() ? textcolor() : inactive(textcolor()));
  49.   fl_font(textfont(), textsize());
  50.   fl_draw(buf,X+3,Y,W-6,H,FL_ALIGN_LEFT);
  51. }
  52.  
  53. int Fl_Value_Output::handle(int event) {
  54.   if (!step()) return 0;
  55.   double v;
  56.   int delta;
  57.   int mx = Fl::event_x();
  58.   static int ix, drag;
  59.   switch (event) {
  60.   case FL_PUSH:
  61.     ix = mx;
  62.     drag = Fl::event_button();
  63.     handle_push();
  64.     return 1;
  65.   case FL_DRAG:
  66.     delta = Fl::event_x()-ix;
  67.     if (delta > 5) delta -= 5;
  68.     else if (delta < -5) delta += 5;
  69.     else delta = 0;
  70.     switch (drag) {
  71.     case 3: v = increment(previous_value(),delta*100); break;
  72.     case 2: v = increment(previous_value(),delta*10); break;
  73.     default:v = increment(previous_value(),delta); break;
  74.     }
  75.     v = round(v);
  76.     handle_drag(soft()?softclamp(v):clamp(v));;
  77.     return 1;
  78.   case FL_RELEASE:
  79.     handle_release();
  80.     return 1;
  81.   default:
  82.     return 0;
  83.   }
  84. }
  85.  
  86. Fl_Value_Output::Fl_Value_Output(int x,int y,int w,int h,const char *l)
  87. : Fl_Valuator(x,y,w,h,l) {
  88.   box(FL_NO_BOX);
  89.   align(FL_ALIGN_LEFT);
  90.   textfont_ = FL_HELVETICA;
  91.   textsize_ = FL_NORMAL_SIZE;
  92.   textcolor_ = FL_BLACK;
  93.   soft_ = 0;
  94. }
  95.  
  96. //
  97. // End of "$Id: Fl_Value_Output.cxx,v 1.6 1999/01/07 19:17:28 mike Exp $".
  98. //
  99.